<?php

namespace App\Http\Controllers\V1;

use AlibabaIdleIsvItemPublishRequest;
use AlibabaIdleIsvMediaUploadRequest;
use AlibabaIdleIsvRateCreateRequest;
use AlibabaIdleItemUserPublishitemsRequest;
use AlibabaIdleLogisticsTemplateCreateRequest;
use AlibabaIdleUserPermitQueryRequest;
use App\Http\Controllers\Controller;
use IdleItemApiAfterSalesDO;
use IdleItemApiBidDo;
use IdleItemApiBizHelpDataDO;
use IdleItemApiBookDo;
use IdleItemApiBrandBargainDO;
use IdleItemApiDo;
use IdleItemApiFlashSaleDO;
use IdleItemApiInspectedDo;
use IdleItemApiPvPairDo;
use IdleItemApiSkuDo;
use IdleItemApiYhbDO;
use IdleItemImageInfoApiDO;
use IdleItemRealCarVerifyDO;
use IdleItemSkuImageInfoApiDO;
use IdleItemTrendyPreSaleDO;
use IdleLogisticsTemplateCreateParam;
use IdleNewPubValueDo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use ItemPageQuery;
use TemplateDetailDTO;
use TmcMessageProduceRequest;
use TmcUserGetRequest;
use TopAuthTokenCreateRequest;
use TopClient;

class Goods extends Controller
{


    public function ceshi(){
        $c = new TopClient;
        $appkey = '34896803';
        $secret = '57181896852db9cf0a64406cd08c5b4f';
        $sessionKey = '50002000b03hVpZ1681089bLowQSccafzGMrZxqC6BAu6qU2GIhOLwEq1nFpwUrZ6x2q';
        $c = new TopClient;
        $c->appkey = $appkey;
        $c->secretKey = $secret;
        $req = new AlibabaIdleIsvItemPublishRequest;
        $item_param = new IdleItemApiDo;
        $item_param->inspect_report="http://inspect_report.html";
        $item_param->images="[]";
        $item_param->reserve_price="35.31";
        $item_param->transport_fee="5.87";
        $item_param->original_price="50.02";
        $item_param->title="iphoneX手机特卖";
        $item_param->stuff_status="95";
        $item_param->sp_biz_type="1";
        $item_param->division_id="330110";
        $item_param->category_id="50025386";
        $item_param->trade_type="0";
        $item_param->desc="全新，红色，超便宜";
        $item_param->latitude="25.82782";
        $item_param->longitude="107.54135";
        $item_param->item_biz_type="0";
        $item_param->ware_house_city="杭州";
        $item_param->ware_house_time="1615863262";
        $item_param->channel_cat_id="12345567";
        $pv_list = new IdleNewPubValueDo;
        $pv_list->property_id="21553";
        $pv_list->property_name="品牌";
        $pv_list->channel_cat_id="1451";
        $pv_list->value_id="12354";
        $pv_list->value_name="Apple/苹果";
        $item_param->pv_list = $pv_list;
        $item_sku_list = new IdleItemApiSkuDo;
        $property_list = new IdleItemApiPvPairDo;
        $property_list->value_text="XL";
        $property_list->property_text="尺码";
        $item_sku_list->property_list = $property_list;
        $item_sku_list->quantity="5";
        $item_sku_list->price="1";
        $item_sku_list->outer_id="123523462";
        $item_param->item_sku_list = $item_sku_list;
        $inspected_data = new IdleItemApiInspectedDo;
        $inspected_data->inspect_report="http://inspect_report.html";
        $inspected_data->ware_house_city="深圳";
        $inspected_data->ware_house_time="1620544846";
        $inspected_data->inspect_report_id="123456";
        $item_param->inspected_data = $inspected_data;
        $book_data = new IdleItemApiBookDo;
        $book_data->barcode="9787111302832";
        $book_data->barcode_name="计算机科学丛书";
        $item_param->book_data = $book_data;
        $item_param->quantity="1";
        $item_param->template_id="40090611110";
        $item_param->outer_id="190085448924";
        $bid_data = new IdleItemApiBidDo;
        $bid_data->bid_start_time="1629949200000";
        $bid_data->bid_end_time="1629953200000";
        $bid_data->bid_bail="2000";
        $bid_data->bid_step="100";
        $item_param->bid_data = $bid_data;
        $item_param->auction_type="b";
        $item_param->white_bg_imgs="13432534565767";
        $item_param->sp_guarantee="1,2,3";
        $after_sales_data = new IdleItemApiAfterSalesDo;
        $after_sales_data->support_sdr_policy="true";
        $after_sales_data->support_nfr_policy="false";
        $after_sales_data->support_vnr_policy="false";
        $after_sales_data->support_fd24hs_policy="false";
        $after_sales_data->support_fd10ms_policy="false";
        $after_sales_data->support_fd48hs_policy="false";
        $after_sales_data->support_gpa_policy="false";
        $item_param->after_sales_data = $after_sales_data;
        $real_car_verify_data = new IdleItemRealCarVerifyDO;
        $real_car_verify_data->driving_license_info="123";
        $real_car_verify_data->driving_license_car_photo="123";
        $real_car_verify_data->business_license_front="123";
        $real_car_verify_data->car_function="营运";
        $real_car_verify_data->car_vin="123123";
        $item_param->real_car_verify_data = $real_car_verify_data;
        $idle_item_yhb_do = new IdleItemApiYhbDO;
        $idle_item_yhb_do->use_yhb_service="true";
        $idle_item_yhb_do->settings_preferences="{}";
        $item_param->idle_item_yhb_do = $idle_item_yhb_do;
        $biz_help_data = new IdleItemApiBizHelpDataDO;
        $biz_help_data->first_phase_order_id="123213";
        $item_param->biz_help_data = $biz_help_data;
        $flash_sale_do = new IdleItemApiFlashSaleDO;
        $flash_sale_do->tag="1";
        $flash_sale_do->food_pro_date="2024-01-01 00:00:00";
        $flash_sale_do->food_expire_date="2024-01-01 00:00:00";
        $item_param->flash_sale_do = $flash_sale_do;
        $item_param->idle_template_id="123";
        $brand_bargain = new IdleItemApiBrandBargainDO;
        $brand_bargain->item_stuff="unused_micro_defects";
        $brand_bargain->produce_date="1709481600000";
        $brand_bargain->shelf_life="180";
        $brand_bargain->supplier="xxx";
        $brand_bargain->cert_pic_id="123";
        $item_param->brand_bargain = $brand_bargain;
        $item_param->inspection_report="123";
        $long_images = new IdleItemImageInfoApiDO;
        $long_images->width="12";
        $long_images->height="12";
        $long_images->file_id="12";
        $item_param->long_images = $long_images;
        $property_images = new IdleItemSkuImageInfoApiDO;
        $property_images->image_id="123";
        $property_images->property_text="颜色";
        $property_images->value_text="红色";
        $item_param->property_images = $property_images;
        $item_param->weight="9.87";
        $item_param->weight_unit="g";
        $trendy_pre_sale_do = new IdleItemTrendyPreSaleDO;
        $trendy_pre_sale_do->dep_model="1";
        $trendy_pre_sale_do->dep_config="10";
        $trendy_pre_sale_do->start_time="1725623518000";
        $trendy_pre_sale_do->end_time="1725623518000";
        $trendy_pre_sale_do->g_time="1725623518000";
        $item_param->trendy_pre_sale_do = $trendy_pre_sale_do;
        $req->setItemParam(json_encode($item_param));
        $resp = $c->execute($req, $sessionKey);

        var_dump($resp);

    }

    public function token(){
        $c = new TopClient;
        $appkey = '34896803';
        $secret = '57181896852db9cf0a64406cd08c5b4f';
        $c->appkey = $appkey;
        $c->secretKey = $secret;
        $req = new TopAuthTokenCreateRequest;
        $req->setCode("0_DzKqyPT71WhmF6NoUHwiJAyz9876");
//        $req->setUuid("abc(如果未使用就别传，绝大多数都不需要传这个参数)");
        $resp = $c->execute($req);
        var_dump($resp);
    }

    /**
     * @param Request $request
     * @return
     */
    public function upload(Request $request){

        $path = '';
        if ($request->hasFile('image')) {
            $image = $request->file('image');
            $filename = time().'_'.$image->getClientOriginalName();
            Storage::disk('public')->put($filename, file_get_contents($image));
            $path = base_path('storage/app/public/'.$filename);

        }
        $appkey = '34896803';
        $secret = '57181896852db9cf0a64406cd08c5b4f';
        $sessionKey = '50000000b06hVpZLow1d0c5d0fQSccafzGMrZxqC6BAu6qU2GIhOLwEq1nFpwUrZ6x2q';
        $c = new TopClient;
        $c->appkey = $appkey;
        $c->secretKey = $secret;
        $req = new AlibabaIdleIsvMediaUploadRequest;
//附件上传的机制参见PHP CURL文档，在文件路径前加@符号即可
        $req->setData('@'.$path);
        $req->setName($filename);
        $req->setType("0");
        $resp = $c->execute($req, $sessionKey);
        var_dump($resp);
        return response('图片上传成功');
    }

}
